#include "PlayerEntity.h"

#include "../Managers/GameService.h"
#include "../Managers/LevelManager.h"

//-------------------------------------------------------------------------------------------
PlayerEntity::PlayerEntity(int team)
	:GameEntity(team)
{
}

//-------------------------------------------------------------------------------------------
PlayerEntity::~PlayerEntity()
{
}

//-------------------------------------------------------------------------------------------
void PlayerEntity::OnNodeReached()
{
	m_pCurrentNodeID = m_pDestinationNodeID;
	
	int newNode = m_pLevelManager->GetNode(m_pCurrentNodeID)->GetConnection(m_currentDir);

	if (newNode == -1)
		return;

	m_pDestinationNodeID = newNode;
	SetProgress(0);
}

//-------------------------------------------------------------------------------------------
void PlayerEntity::Tick(float DeltaTime)
{
}

//-------------------------------------------------------------------------------------------
bool PlayerEntity::OnInput(sf::Event::KeyEvent* pKeyEvent, bool keyDown)
{
	if (keyDown)
	{
		switch(pKeyEvent->code)
		{
		case sf::Keyboard::Up:
			{
				m_currentDir = Node::Direction::UP;
			}break;
		case sf::Keyboard::Down:
			{
				m_currentDir = Node::Direction::DOWN;
			}break;
		case sf::Keyboard::Left:
			{
				m_currentDir = Node::Direction::LEFT;
			}break;
		case sf::Keyboard::Right:
			{
				m_currentDir = Node::Direction::RIGHT;
			}break;
		}
	}
	else
	{
		m_currentDir = Node::Direction::NONE;
	}

	return true;
}

//-------------------------------------------------------------------------------------------